﻿using SqlSugar;
using System.Reflection;

namespace ProductionManagement.Infrstructre
{
    public class SqlSugarDBcontext
    {
        protected readonly ISqlSugarClient db;

        public SqlSugarDBcontext(ISqlSugarClient db)
        {
            this.db = db;
        }
        public void CreateDatabase()
        {
            db.DbMaintenance.CreateDatabase();
            var rootBath = AppDomain.CurrentDomain.BaseDirectory;
            Type[] types = Assembly
                .LoadFrom(rootBath + "ProductionManagement.Domain.dll")
                .GetTypes().Where(it => it.FullName.Contains("ProductionManagement.Domain.ProductionDomain"))
                .ToArray();

            db.CodeFirst.SetStringDefaultLength(200).InitTables(types);
        }
    }
}
